/**
 * @author Nicolas Zimerman (zimerman@usi.ch)
 * @author Isabella Nake (isabella.nake@usi.ch)
 * @author Nicolas Lusa (lusan@usi.ch)
 * @author Nicolas Latorre (nicolas.latorre@usi.ch)
 */
package ch.usi.inf.pf2.circuit;

import java.awt.Graphics;

public class Output extends Component {
	private static final long serialVersionUID = 586731168780329289L;
	private int x1;
	private int y1;
	
	private Wire wire;
	private InputPinForOutput inputPin;
	
	private String color;
	
	public Output(final int x, final int y) {
		
		wire = null;
		inputPin = null;
		
		this.x1 = x;
        this.y1 = y;
        
        color = "black";
	
	}
	
	//MODEL PART
	
	public void setWire(final Wire wire) {
		this.wire = wire;
		inputPin = new InputPinForOutput(this);
		wire.setInputPin(inputPin);
	}
	
	public InputPin getInputPin() {
		return inputPin;
	}
	
	@Override
	public Wire[] getWires() {
		return new Wire[] {wire};
	}
	
	public void removeInputPin() {
		inputPin = null;
	}
	
	//GUI PART
	
	public int getOriginX() {
        return x1;
    }
    
    public int getOriginY() {
        return y1 + 7;
    }

    public void draw(final Graphics g) {
    	g.drawOval(x1, y1, 15, 15);
    }
    
    public boolean contains(final int x, final int y) {
        return x>=x1 && x<=x1+15 && y>=y1 && y<=y1+15;
    }

	@Override
	public void move(final int deltaX, final int deltaY) {
		x1 += deltaX;
		y1 += deltaY;
		
		if(wire != null) {
			wire.moveXY2(deltaX, deltaY);
		}
	}

	public void printValue(final Value value) {
		System.out.println("The final result is: " + value);
		if(value == Value.TRUE) {
			color = "green";
		} else if(value == Value.FALSE) {
			color = "blue";
		} else {
			color = "black";
		}
	}
	
	public String getColor() {
		return color;
	}

	public String toString() {
        return "Output";
    }

	
	
}
